import axios from 'axios';

var service = axios.create(
    {
        baseURL: '/api', timeout: 10000
    }
)
//设置请求拦截器
service.interceptors.request.use((config) => {
    config.headers['Authorization'] = 'Bearer' + ' ' + localStorage.getItem('token');
    return config;
}, (error) => {
    return Promise.reject(error);
})
// 设置响应拦截器
service.interceptors.response.use((res) => {
    return res;
}, (error) => {
    if (error.response.status === 401) {
        alert('身份认证已过期，请重新登录');
    } else if (error.response.status === 404) {
        alert('请求资源不存在');
    } else if (error.response.status === 500) {
        alert("服务器内部错误")
    }
})
export default service;